﻿<UserControl x:Class="MContracts.View.ActsRepositoryView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="1000" 
             xmlns:converters="clr-namespace:MContracts.Classes.Converters"
             xmlns:vm="clr-namespace:MContracts.ViewModel"
             xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" DataContext="{Binding}">

    <UserControl.Resources>
        <Style TargetType="Button">
            <Setter Property="Margin" Value="2"/>
            <Setter Property="Width" Value="24"/>
            <Setter Property="Height" Value="24"/>
        </Style>
        
        <converters:CurrencyConverter x:Key="CurrencyConverter1" />
        <converters:DateTimeToDateConverter x:Key="DateTimeToDateConverter" />
        <converters:DateTimeToShortDateConverter x:Key="DateTimeToShortDateConverter"/>
        <converters:ContractdocConverter x:Key="ContractdocConverter"/>
        <converters:ContractToVisibilityConverter x:Key="ContractToVisibilityConverter"/>
        <converters:ActSignedToImageConverter x:Key="ActSignedToImageConverter"/>        

        <Style x:Key="GroupHeaderStyle" TargetType="{x:Type GroupItem}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type GroupItem}">
                        <Expander IsExpanded="True" Background="#B9D1EA" BorderBrush="CadetBlue" BorderThickness="0, 1, 0, 0" Foreground="#FF10257F">
                            <Expander.Header>
                                <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
                                    <TextBlock VerticalAlignment="Center" Margin="5, 0, 0, 0" x:Name="PropertyTextBlock" Text="{Binding Name}" FontSize="12" FontWeight="Bold"/>
                                    <Button ToolTip="Добавить акт" Click="Button_Click" Visibility="{Binding Name, Converter={StaticResource ContractToVisibilityConverter}}">
                                        <Image Source="/MContracts;component/Resources/act_add.png"/>
                                    </Button>
                                    <Button ToolTip="Редактировать акт" Command="{Binding DataContext.EditActCommand, RelativeSource={RelativeSource AncestorType=UserControl}}" Visibility="{Binding Name, Converter={StaticResource ContractToVisibilityConverter}}">
                                        <Image Source="/MContracts;component/Resources/act_edit.png" />
                                    </Button>
                                    <Button ToolTip="Вывести акт на печать" Command="{Binding DataContext.CreateActReportCommand, RelativeSource={RelativeSource AncestorType=UserControl}}" Visibility="{Binding Name, Converter={StaticResource ContractToVisibilityConverter}}">
                                        <Image Source="/MContracts;component/Resources/document.png" />
                                    </Button>
                                </StackPanel>
                            </Expander.Header>
                            <ItemsPresenter/>
                        </Expander>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>

    <Grid>
        
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition Height="25"/>
        </Grid.RowDefinitions>

        <DockPanel LastChildFill="True">

            <StackPanel DockPanel.Dock="Left" Width="1"/>
            <StackPanel DockPanel.Dock="Right" Width="1"/>

            <telerik:RadGridView 
                      ItemsSource="{Binding EntitiesView, Mode=OneWay}" 
                      AutoGenerateColumns="False" 
                      x:Name="ActsDataGrid" SelectionMode="Extended" 
                      ShowColumnFooters="True"  
                      SelectedCellsChanged="ActsDataGrid_SelectedCellsChanged" SelectionUnit="FullRow"
                      RowIndicatorVisibility="Collapsed"                  
                      ShowColumnHeaders="True"
                      IsReadOnly="True">

                <telerik:RadGridView.Columns>
                    <telerik:GridViewDataColumn Width="Auto">
                        <telerik:GridViewDataColumn.CellTemplate>
                            <DataTemplate>
                                <Image Width="20" Height="20" Margin="2" ToolTip="{Binding Path=Act.Signedstring}" Source="{Binding Path=Act.IssignedBool, Converter={StaticResource ActSignedToImageConverter}}"/>
                            </DataTemplate>
                        </telerik:GridViewDataColumn.CellTemplate>
                    </telerik:GridViewDataColumn>
                    <telerik:GridViewDataColumn Header="№ договора" DataMemberBinding="{Binding ContractNum}" IsGroupable="True" GroupMemberPath="ContractNum" Width="Auto" />
                    <telerik:GridViewDataColumn Header="№ акта" DataMemberBinding="{Binding ActNum}" Width="Auto" IsGroupable="False"/>
                    <telerik:GridViewDataColumn Header="Дата подписания" DataMemberBinding="{Binding SignDate, StringFormat=d}" Width="Auto" IsGroupable="False"/>
                    <telerik:GridViewDataColumn Header="Этапы КП" DataMemberBinding="{Binding StageNums}" Width="Auto" IsGroupable="False" />
                    <telerik:GridViewDataColumn Header="Сумма c НДС" DataMemberBinding="{Binding Path=WithNdsPrice}" Width="Auto" IsGroupable="False" />
                    <telerik:GridViewDataColumn Header="Сумма без НДС" DataMemberBinding="{Binding Path=PurePrice}" Width="Auto" IsGroupable="False"/>
                    <telerik:GridViewDataColumn Header="НДС" DataMemberBinding="{Binding Path=NdsPrice}" Width="Auto" IsGroupable="False"/>
                    <telerik:GridViewDataColumn Header="Аванс" DataMemberBinding="{Binding Credited}" Width="Auto" IsGroupable="False"/>
                    <telerik:GridViewDataColumn Header="К перечислению" DataMemberBinding="{Binding Path=TransferSum}" Width="Auto" IsGroupable="False"/>
                    <telerik:GridViewDataColumn Header="Дата договора" DataMemberBinding="{Binding Path=ContractSignDate, StringFormat=d}" Width="Auto" IsGroupable="False"/>
                    <telerik:GridViewDataColumn Header="Исполнитель" DataMemberBinding="{Binding Path=Contractor}" Width="Auto" IsGroupable="True"/>
                </telerik:RadGridView.Columns>
            </telerik:RadGridView>
        </DockPanel>

        <StatusBar Grid.Row="1">
            <TextBlock Text="Всего актов -" FontWeight="Bold"/>
            <TextBlock Text="{Binding ActsCount}"/>
            <Separator/>
            
            <TextBlock Text="Итого " FontWeight="Bold"/>

            <TextBlock Text="С НДС: "/>
            <TextBlock Text="{Binding ActsPriceSum}"/>
            <Separator/>
            
            <TextBlock Text="Без НДС: "/>
            <TextBlock Text="{Binding SumPure}"/>
            <Separator/>

            <TextBlock Text="НДС: "/>
            <TextBlock Text="{Binding SumNDS}"/>
            <Separator/>

            <TextBlock Text="Сумма аванса: " FontWeight="Bold"/>
            <TextBlock Text="{Binding CreditedSum}"/>
            <Separator/>

            <TextBlock Text="Сумма к перечислению: " FontWeight="Bold"/>
            <TextBlock Text="{Binding TransferPriceSum}"/>
            <Separator/>
        </StatusBar>

    </Grid>
</UserControl>

    
